package com.example.com.transcribeeditpublish.popuWindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.example.com.transcribeeditpublish.R;
import com.example.com.transcribeeditpublish.activity.VideoEditActivity;
import com.tencent.ugc.TXVideoEditer;

public class SetVoicePpWindow extends PopupWindow {
    private final VideoEditActivity mVideoActivity;
    private final View bgmVolume;

    public SetVoicePpWindow(VideoEditActivity context) {
        this.mVideoActivity = context;
        View mMenuView = LayoutInflater.from(mVideoActivity).inflate(R.layout.popuwindow_setting_voice, null, false);

        bgmVolume = mMenuView.findViewById(R.id.bgm_container);
        initListener(mMenuView);
        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //适配虚拟键
        this.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0x00000000); //android:background="#30000000"
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
    }

    public void show(VideoEditActivity context) {
        boolean haseBGM = mVideoActivity.haseBGM();
        bgmVolume.setVisibility(haseBGM ? View.VISIBLE : View.GONE);
        this.showAtLocation(context.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
    }

    private void initListener(final View mMenuView) {
        ((SeekBar) mMenuView.findViewById(R.id.seekBar_voice_volume)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                TXVideoEditer txCameraRecord = mVideoActivity.getTXCameraRecord();
                txCameraRecord.setVideoVolume(progress / 100F);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        ((SeekBar) mMenuView.findViewById(R.id.seekBar_bgm_volume)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                TXVideoEditer txCameraRecord = mVideoActivity.getTXCameraRecord();
                txCameraRecord.setBGMVolume(progress / 100F);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });


    }

}
